# -*- coding: utf-8 -*-
"""
PBAR_ExamineZspecPause.py

Created on Fri May 02 13:40:50 2014

@author: jkwong
"""

# define good/bad detectors
(goodZspecMask, badZspecMask, goodZspecNameList, badZspecNameList, \
        goodZspecIndices, badZspecIndices) = PBAR_Zspec.ZspecDetectorLists2ndSet()


datPath = r'E:\PBAR\Misc'
filenameList = []
filenameList.append('201405011617cal.csv')
filenameList.append('201405011639cal.csv')
filenameList.append('201405011655cal.csv')

fullfilenameList =[]
for f in filenameList:
    fullfilenameList.append(os.path.join(datPath, f))

dat = []
for f in fullfilenameList:
    dat.append(PBAR_Zspec.ReadZspec(f)[0])
    

# make plots

# Plot spectrum from several channels, all datasets

detCh = 60;
plt.figure()
plt.grid()

for i in xrange(len(dat)):
    plt.plot(dat[i][:,detCh], label = '%s, ch %d' %(filenameList[i], detCh+1))
plt.xlim((0, 200))
plt.yscale('log')    
plt.xlabel('Bin', fontsize = 16)
plt.ylabel('Counts', fontsize = 16)

plt.legend(prop={'size':12})


# plot sum of counts in tail vs detector number

plt.figure()
plt.grid()

for i in xrange(len(dat)):
    plt.plot(np.arange(1, 137)[goodZspecMask], dat[i][100:-1,:].sum(0)[goodZspecMask], marker = 'x', label = '%s, ch %d' %(filenameList[i], detCh+1))
plt.xlim((0, 136))
#plt.yscale('log')
plt.xlabel('Detector Number', fontsize = 16)
plt.ylabel('Counts (bin >= 100)', fontsize = 16)

plt.legend(prop={'size':12})
